package cn.signalpha.modules.base.controller.api;

import cn.signalpha.core.boot.ctrl.BaseController;
import cn.signalpha.common.constant.AppConstant;
import cn.signalpha.core.tool.api.R;
import cn.signalpha.core.tool.utils.ObjectUtil;
import cn.signalpha.modules.base.entity.Help;
import cn.signalpha.modules.base.service.HelpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 控制器
 *
 * @author signalpha
 */
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_BASE_NAME + "/wap/help")
@Api(value = "帮助中心", tags = "帮助中心")
public class ApiHelpController extends BaseController {

	private final HelpService helpService;

    @GetMapping("/list")
    @ApiOperation(value = "帮助中心", notes = "传入编码")
    public R<List<Help>> list(@ApiParam(value = "编码") @RequestParam(required = false) String code) {
        return R.data(helpService.listCache(code));
    }

	@GetMapping("/info")
	@ApiOperation(value = "服务协议", notes = "传入编码")
	public R<Help> info(@ApiParam(value = "编码", required = true) @RequestParam String code) {
		List<Help> list = helpService.listCache(code);
		return R.data(ObjectUtil.isEmpty(list) ? null : list.get(0));
	}

}
